---@class DIYUtility
local DIY = require "packages/diy_utility/diy_utility"

local hushenzhoufa = fk.CreateSkill{
    name = "ym2__hushenzhoufa",
    tags = {DIY.ReadySkill}
}
Fk:loadTranslationTable{
    ["ym2__hushenzhoufa"] = "护身咒法",
    [":ym2__hushenzhoufa"] = "<a href='diy_ready_skill'>蓄势技</a>，回合结束时，你可以获得三张于你成为【杀】的目标后，你摸牌后，你的回合开始时弃置一张的【闪】。",
    ["#ym2__hushenzhoufa-discard"] = "护身咒法：弃置其中一张牌",
    ["@@ym2__hushenzhoufa-inarea"] = "护身咒",

    ["$ym2__hushenzhoufa1"] = "有人以为在用自己的记忆创建我，可是他的记忆是我创建的",
    ["$ym2__hushenzhoufa2"] = "真让人害怕，骗你哒",
}
hushenzhoufa:addEffect(fk.TurnEnd,{
    anim_type = "defensive",
    can_trigger = function (self, event, target, player, data)
        return player == target and player:hasSkill(hushenzhoufa.name)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = room:getCardsFromPileByRule("jink", 3, "allPiles")
        if #cards > 0 then
            player.room:obtainCard(player, cards, true, fk.ReasonJustMove, player, hushenzhoufa.name, "@@ym2__hushenzhoufa-inarea")
        end
    end,
})
local spec = {
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local ids = table.filter(player.player_cards[Player.Hand],function (cardId, index, array)
            local card = Fk:getCardById(cardId)
            return card:getMark("@@ym2__hushenzhoufa-inarea") > 0
        end)
        p(tostring(Exppattern{id = ids}))
        room:askToDiscard(player,{
            max_num = 1,
            min_num = 1,
            cancelable = false,
            skill_name = hushenzhoufa.name,
            pattern = tostring(Exppattern{id = ids}),
            prompt = "#ym2__hushenzhoufa-discard",
        })
    end,
}
hushenzhoufa:addEffect(fk.AfterCardsMove,{
    can_refresh = function (self, event, target, player, data)
        if #table.filter(player.player_cards[Player.Hand],function (cardId, index, array)
            local card = Fk:getCardById(cardId)
            return card:getMark("@@ym2__hushenzhoufa-inarea") > 0
        end) > 0 then
            for _, move in ipairs(data) do
                if move.to == player and move.moveReason == fk.ReasonDraw then
                    return true
                end
            end
        end
    end,
    on_refresh = spec.on_refresh
})
hushenzhoufa:addEffect(fk.TurnStart,{
    can_refresh = function (self, event, target, player, data)
        if #table.filter(player.player_cards[Player.Hand],function (cardId, index, array)
            local card = Fk:getCardById(cardId)
            return card:getMark("@@ym2__hushenzhoufa-inarea") > 0
        end) > 0 then
            return player == target
        end
    end,
    on_refresh = spec.on_refresh
})
hushenzhoufa:addEffect(fk.TargetConfirmed, {
    can_refresh = function(self, event, target, player, data)
        if #table.filter(player.player_cards[Player.Hand],function (cardId, index, array)
            local card = Fk:getCardById(cardId)
            return card:getMark("@@ym2__hushenzhoufa-inarea") > 0
        end) > 0 then
            return target == player and data.card.trueName == "slash"
        end
    end,
    on_refresh = spec.on_refresh
})
return hushenzhoufa